package org.filetransfer.file_transfer_java_backend.controller;

import lombok.RequiredArgsConstructor;
import org.filetransfer.file_transfer_java_backend.service.StatService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Map;

@RestController
@RequestMapping("/api/stat")
@RequiredArgsConstructor
public class StatController {

    private final StatService statService;

    // 获取某个类型的统计信息（今日 + 总量）
    @GetMapping("/{type}")
    public Map<String, Long> getTypeStats(@PathVariable String type) {
        long today = statService.getTodayCount(type);
        long total = statService.getTotalCount(type);
        return Map.of("today", today, "total", total);
    }

    // 获取所有类型统计（today + total）
    @GetMapping("/overview")
    public Map<String, Map<String, Long>> getAllTypeStats() {
        return statService.getAllStats(); // 你需要实现 getAllStats()
    }

    // 获取某类型在某时间段内的每日统计
    @GetMapping("/{type}/range")
    public Map<LocalDate, Long> getRangeStats(
            @PathVariable String type,
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate
    ) {
        return statService.getStatsInRange(type, startDate, endDate);
    }
}
